package com.lunwen.lunwen.config;

import com.lunwen.lunwen.bean.Result;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ShiroException {

    /**
     * 登录认证异常
     * @return
     */
    @ExceptionHandler({ UnauthenticatedException.class, AuthenticationException.class })
    public Result authenticationException() {
        Result result = new Result();
        result.setCode("-1000");
        result.setMessage("未登录");
        return result;
    }

    /**
     * 权限异常
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    public Result authorizationException (){
        Result result = new Result();
        result.setCode("-1001");
        result.setMessage("无权限");
        return result;
    }

//    @ExceptionHandler(Exception.class)
//    public Result handleException(Exception e){
//        System.out.println(e.getMessage());
//        Result result = new Result();
//        result.setCode("-1002");
//        return result;
//    }

}